/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.service.system.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.pages.PageTools;
import org.grayrabbit.pay.core.service.system.TradeTerminalService;
import org.grayrabbit.pay.core.dao.system.TradeTerminalDao;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeTerminalServiceImpl.java, v 0.1 Sat Jun 02 22:00:25 CST 2012 liyd Exp $
 */
@Component
public class TradeTerminalServiceImpl implements TradeTerminalService {

    @Autowired
    private TradeTerminalDao tradeTerminalDao;

    /**
     * 查询业务对象列表
     * 
     * @param tradeTerminal
     * @return
     */
    public PageList<TradeTerminal> queryPageList(TradeTerminal tradeTerminal) {

        PageTools pageTools = new PageTools();
        pageTools.setPage(tradeTerminal.getPageNum());
        pageTools.setItemsPerPage(tradeTerminal.getPageSize());

        Map<String, Object> params = new HashMap<String, Object>();

        params.put("query", tradeTerminal);
        params.put("startRow", pageTools.getBeginIndex());
        params.put("pageSize", pageTools.getItemsPerPage());

        pageTools.setItems(tradeTerminalDao.queryCount(params));

        PageList<TradeTerminal> pageList = new PageList<TradeTerminal>();
        pageList.addAll(tradeTerminalDao.queryPageList(params));
        pageList.setPageTools(pageTools);

        return pageList;

    }

   
    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public TradeTerminal getById(Long id) {

        return tradeTerminalDao.getById(id);
    }


    public int getCountByTerminalCode(String terminalCode) {
        return tradeTerminalDao.getByTerminalCode(terminalCode).size();
    }
    
    @Override
    public TradeTerminal getByTerminalCode(String terminalCode) {
        List<TradeTerminal> list = tradeTerminalDao.getByTerminalCode(terminalCode);
        return list.isEmpty()?null:list.get(0);
    }


    /**
     * 根据id批量删除
     * 
     * @param idArray
     */
    public void deleteBatchById(Long[] idArray) {
        tradeTerminalDao.deleteBatchById(idArray);
    }

    /**
     * 查询所有对象
     * 
     * @return
     */
    public List<TradeTerminal> findAll() {
        return tradeTerminalDao.findAll();
    }

    public List<TradeTerminal> findEnabledTerminals() {
        return tradeTerminalDao.findEnabledTerminals();
    }

    /**
     * 添加一个对象
     * 
     * @param tradeTerminal
     */
    public void insert(TradeTerminal tradeTerminal) {

        tradeTerminalDao.save(tradeTerminal);

    }

    /**
     * 更新一个对象
     * 
     * @param tradeTerminal
     * @return
     */
    public int update(TradeTerminal tradeTerminal) {

        return tradeTerminalDao.update(tradeTerminal);

    }

    public int changeStatus(TradeTerminal tradeTerminal) {

        return tradeTerminalDao.changeStatus(tradeTerminal);

    }

    /**
     * 删除一个对象
     * 
     * @param tradeTerminal
     */
    public void delete(TradeTerminal tradeTerminal) {
        tradeTerminalDao.delete(tradeTerminal);
    }

}
